package dao.Impl;

import dao.CourseDao;
import po.Course;
import util.DBUtils;
import util.DaoRepeat;

import java.sql.SQLException;
import java.util.List;

public class CourseDaoImpl extends BaseDaoImpl<Course> implements CourseDao {
    @Override
    public boolean insert(Course course) {
        try {
            insert(course, DBUtils.getConnection());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  true;
    }

    @Override
    public boolean delete(Course course) {
        try {
            delete(course,DBUtils.getConnection());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  true;
    }


    @Override
    public List<Course> queryAllCourse(Integer collegeId,Integer gradeId) {
        List<Course> courses = queryMany("select * from  Course where collegeId=? and gradeId=?", Course.class, collegeId,gradeId);
        return  courses;
    }

    @Override
    public Course queryOne(Integer id) {
        Course course = queryOne("select * from Course where id=?", Course.class, id);
        return  course;
    }




    @Override
    public String getBeginTime(Integer cid) {
        DaoRepeat<Course> daoRepeat = new DaoRepeat<>();
        String begintime = daoRepeat.getStringExecuteSQL("beginTime", "select * from Course where id=?", cid);
        return  begintime;
    }

    @Override
    public boolean update(Course course) {
        try {
            update(course,DBUtils.getConnection());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return true;
    }


}
